package com.ln.property_control.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ln.property_control.mapper.CheckPlanMapper;
import com.ln.property_control.pojo.*;
import com.ln.property_control.service.CheckPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
/*盘点计划业务处理层*/
public class CheckPlanServiceImpl implements CheckPlanService {

    @Autowired
    private CheckPlanMapper checkPlanMapper;

    /*展示所有盘点计划，并完成分页*/
    @Override
    public Map<String, Object> selecyAllPlan(Integer page , Integer  limit) {
        /*创建Map集合用于存放数据，及所需的页码数*/
        Map<String, Object> map = new HashMap<>();
        Page<Object> pageObj = PageHelper.startPage(page, limit);
        List<CheckPlanVo> propertyVoList = checkPlanMapper.selecyAllPlan();
        map.put("data", propertyVoList);
        map.put("code", 0);
        long total = pageObj.getTotal();
        map.put("count", total);
        return map;
    }

    @Override
    public CheckPlanVo selectByCheckID(String checkplanID) {
      return   checkPlanMapper.selectByCheckID(checkplanID);
    }

    @Override
    public List<PropertyVo> selectPropertyByID(String checkplanID) {
        return checkPlanMapper.selectPropertyByID(checkplanID);
    }

    @Override
    public List<Department> selectDeByID() {
        return checkPlanMapper.selectDeByID();
    }

    @Override
    public List<PropertyVo> selectProTypeByID() {
        return checkPlanMapper.selectProTypeByID();
    }

    @Override
    public List<CheckPlanType> selectCheckTypeByID() {
        return checkPlanMapper.selectCheckTypeByID();
    }

    @Override
    public List<PropertyVo> selectByDepIDorTypeID(Integer property_dep_id, Integer property_tid) {
        return checkPlanMapper.selectByDepIDorTypeID(property_dep_id, property_tid);
    }

    @Override
    public void addCheckPlan(CheckPlan checkPlan) {
        checkPlanMapper.addCheckPlan(checkPlan);
    }


    @Override
    public void updateCheck(CheckPlan checkPlan) {
        checkPlanMapper.updateCheck(checkPlan);
    }

    @Override
    public int insertAccPlan(History_plan history_plan) {
        return checkPlanMapper.insertAccPlan(history_plan);
    }

    @Override
    public void exmaCheckPlan(CheckPlan checkPlan, History_plan history_plan) {
        /*将完成审批的计划从计划表中删除*/
        checkPlanMapper.delCheckPlanID(checkPlan.getCheckplan_id());
        /*将完成的计划编号赋值给历史表对象*/
        history_plan.setHistory_plan_id(checkPlan.getCheckplan_id());
        /*将已完成的计划添加到历史表中*/
        checkPlanMapper.insertAccPlan(history_plan);
    }

    @Override
    public Map<String, Object> selectHistory(Integer page , Integer  limit,String approver_time, String history_plan_name) {
        /*创建Map集合用于存放数据，及所需的页码数*/
        Map<String, Object> map = new HashMap<>();
        Page<Object> pageObj = PageHelper.startPage(page, limit);
        List<History_plan> history_planList = checkPlanMapper.selectHistory(approver_time,history_plan_name);
        map.put("data", history_planList);
        map.put("code", 0);
        long total = pageObj.getTotal();
        map.put("count", total);
        return map;
    }

    @Override
    public Map<String, Object> selectAllProperty(Integer page, Integer limit,Integer present_dep_id, String property_name) {
        /*创建Map集合用于存放数据，及所需的页码数*/
        Map<String, Object> map = new HashMap<>();
        Page<Object> pageObj = PageHelper.startPage(page, limit);
        List<PropertyVo> history_planList = checkPlanMapper.selectAllProperty(present_dep_id, property_name);
        map.put("data", history_planList);
        map.put("code", 0);
        long total = pageObj.getTotal();
        map.put("count", total);
        return map;
    }

    @Override
    public List<Department> findDep() {
        return checkPlanMapper.findDep();
    }

    @Override
    public Map<String,Object> selectByDep(Integer page, Integer limit,Integer did,Integer rankNum) {
        /*创建Map集合用于存放数据，及所需的页码数*/
        Map<String, Object> map = new HashMap<>();
        Page<Object> pageObj = PageHelper.startPage(page, limit);
        List<CheckPlanVo> checkPlanVoList = checkPlanMapper.selectByDep(did,rankNum);
        map.put("data", checkPlanVoList);
        map.put("code", 0);
        long total = pageObj.getTotal();
        map.put("count", total);
        return map;
    }

    @Override
    public List<PropertyType> findPropertyType() {
        return checkPlanMapper.findPropertyType();
    }

    @Override
    public void addResMar(Result_remark result_remark) {
        checkPlanMapper.addResMar(result_remark);
    }

    @Override
    public List<Result_remark> findCheckID(String check_id) {
        return checkPlanMapper.findCheckID(check_id);
    }


}
